import { debounce } from 'lodash-es'

/**
 * @function   防抖指令
 * @example    <button v-debounce:1500="() =>{handleClick()}">防抖指令</button>
 */
export default {
	mounted(el: any, binding: { arg: number; value: any }) {
		const delay = binding.arg || 500
		const callback = binding.value
		el.addEventListener(
			'click',
			debounce(callback, delay, {
				leading: true,
				trailing: false,
			})
		)
	},
}
